package com.github.tvbox.osc.ui.adapter;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.github.tvbox.osc.R;
import com.github.tvbox.osc.bean.Movie;
import com.github.tvbox.osc.picasso.RoundTransformation;
import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.ImgUtil;
import com.github.tvbox.osc.util.MD5;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import io.github.source.media.bean.MediaBean;
import me.jessyan.autosize.utils.AutoSizeUtils;

/**
 * @author pj567
 * @date :2020/12/21
 * @description:
 */
public class GridAdapter extends BaseQuickAdapter<MediaBean, BaseViewHolder> {
    public int mode = 0;

    public GridAdapter() {
        super(R.layout.item_grid, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, MediaBean item) {
        // 年份
        if (item.getVodYear() == null) {
            helper.setVisible(R.id.tvYear, false);
        } else {
            helper.setVisible(R.id.tvYear, true);
            helper.setText(R.id.tvYear, String.valueOf(item.getVodYear()));
        }

        // 区域
        if (item.getVodArea() == null) {
            helper.setVisible(R.id.tvArea, false);
        } else {
            helper.setVisible(R.id.tvArea, true);
            helper.setText(R.id.tvArea, String.valueOf(item.getVodArea()));
        }
        // 语言
        helper.setVisible(R.id.tvLang, false);

        // 备注
        if (TextUtils.isEmpty(item.getVodRemarks())) {
            helper.setVisible(R.id.tvNote, false);
        } else {
            helper.setVisible(R.id.tvNote, true);
            helper.setText(R.id.tvNote, item.getVodRemarks());
        }

        // 名称和演员
        helper.setText(R.id.tvName, item.getVodName());
        helper.setText(R.id.tvActor, item.getVodActor());

        // 图片
        ImageView ivThumb = helper.getView(R.id.ivThumb);
        // 由于部分电视机使用Glide报错(这个解析图片地址步骤有点多)
        ImgUtil.load(item.getVodPic(), ivThumb);

        // 注释掉的模糊背景代码
//    Drawable bitmapDrawable2 = ImgUtil.createFrostedGlassDrawable(mContext, AutoSizeUtils.mm2px(mContext, 300), AutoSizeUtils.mm2px(mContext, 400), 25, 50);
//    helper.getView(R.id.tvName).setBackground(bitmapDrawable2);
    }
}